import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/base/BaseRepository.dart';
import 'package:play_android/com/zhihaoliang/const/AppApi.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpRequest.dart';
import 'package:play_android/com/zhihaoliang/play/hotpage/model/hotkey/HotKeyItem.dart';
import 'package:play_android/com/zhihaoliang/play/hotpage/model/hotkey/HotKeyModel.dart';

///  ***************************************************************************
///  "热门搜索"请求处理
///  ***************************************************************************

class HotKeyPresenter extends BaseRepository<List<HotKeyItem>> {
  HotKeyCallBack _callBack;

  HotKeyPresenter(this._callBack);

  load() {
    fetch()
        .then((list) => _callBack.onLoadHotKeyComplete(list))
        .catchError((onError) => _callBack.onLoadHotKeyeError(onError));
  }

  @override
  List<HotKeyItem> fetchModel(Map<String, dynamic> map) {
    HotKeyModel hotKeyModel = HotKeyModel.fromJson(map);
    return hotKeyModel.data;
  }

  @override
  Future<ResultData> fetchResultData(
      [String url, Map<String, dynamic> map]) async {
    return await HttpRequest().get(AppApi.HOTKEY);
  }
}

abstract class HotKeyCallBack {
  void onLoadHotKeyComplete(List<HotKeyItem> list);

  void onLoadHotKeyeError(HttpException httpException);
}
